package app.view.component.movie 
{
	import com.greensock.TweenLite;
	import com.greensock.TweenMax;
	import com.Utils;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.geom.Point;
	/**
	 * ...
	 * @author PHANCUONG87
	 */
	public class ItemContainer extends MovieClip
	{
		public var nha1:McNha1;
		public var nha2:McNha2;
		public var cay1:McCay;
		public var cay2:McCay;
		public var isFirst:Boolean = true;
		
		public function ItemContainer() 
		{
			this.addEventListener(Event.ADDED_TO_STAGE, addStage);
		}
		
		private function addStage(evt:Event):void {
			this.removeEventListener(Event.ADDED_TO_STAGE, addStage);
			
			nha1 = new McNha1();
			nha1.x = -150;
			nha1.y = stage.stageHeight - 300;
		
			nha1.ot 	= { x:nha1.x, y:nha1.y, scaleX:1, scaleY:1 };
			nha1.oe 	= { x:380, y:360, scaleX:0.2, scaleY:0.2, delay:3, time:15 };
			this.addChild(nha1);
			
			
			
			cay1 = new McCay();
			cay1.x = -250;
			cay1.y = stage.stageHeight;
			cay1.ot 	= { x:cay1.x, y:cay1.y, scaleX:1, scaleY:1 };
			cay1.oe 	= { x:500, y:400, scaleX:0.1, scaleY:0.1, delay:13, time:20 };
			this.addChild(cay1);
			
			
			
			nha2 = new McNha2();
			nha2.x = stage.stageWidth + 200;
			nha2.y = stage.stageHeight - 300;
			nha2.ot 	= { x:nha2.x, y:nha2.y, scaleX:1, scaleY:1 };
			nha2.oe 	= { x:680, y:380, scaleX:0.1, scaleY:0.1, delay:18, time:20 };
			this.addChild(nha2);
			
			cay2 = new McCay();
			cay2.x = stage.stageWidth + 340;
			cay2.y = stage.stageHeight + 100;
			cay2.ot 	= { x:cay2.x, y:cay2.y, scaleX:1, scaleY:1 };
			cay2.oe 	= { x:620, y:400, scaleX:0.1, scaleY:0.1, delay:7, time:20 };
			this.addChild(cay2);
			
		}
		
		private function loopMovie(movie:*):void {
			movie.x = movie.ot.x;
			movie.y = movie.ot.y;
			movie.scaleX = movie.ot.scaleX;
			movie.scaleY = movie.ot.scaleY;
			TweenMax.to(movie, movie.oe.time, {delay:movie.oe.delay, scaleX:movie.oe.scaleX, scaleY:movie.oe.scaleY, x:movie.oe.x, y:movie.oe.y, onComplete:loopMovie, onCompleteParams:[movie] } );
		}
		
		public function pause():void 
		{
			TweenMax.pauseAll();
		}
		
		public function resume():void 
		{
			
			if (isFirst) {
				isFirst = false;
				loopMovie(nha1);
				loopMovie(nha2);
				loopMovie(cay1);
				loopMovie(cay2);
			}else {
				TweenMax.resumeAll();
			}
		}
	}

}